package cn.tedu._05interceptor.base.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import cn.tedu._05interceptor.base.interceptor.MyInterceptor;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截所有
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/v1/**");*/
        //拦截指定模块
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/v1/user/**");*/
        //拦截指定方法
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/v1/user/reg");*/
        //拦截多个方法
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/v1/user/reg","/v1/user/login");*/
        //排除指定方法
        registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/v1/user/**")
                .excludePathPatterns("/v1/user/reg");
    }
}
